package com.dalin.platform.report.service.imple;

import java.io.File;

import com.dalin.common.report.fcharts.PieChart;
import com.dalin.common.utils.FileUtils;
import com.dalin.common.utils.NumberUtils;
import com.dalin.common.utils.TextUtils;
import com.dalin.platform.report.service.WsReportService;

public class ReportServiceImple implements WsReportService {
	private static Long srialNumber = 1L;
	
	public String getPieChartUrl(PieChart chart) throws Exception {
		String pp = FileUtils.getResourcePath();
		pp = pp.substring(0, pp.length() - 16);
		String rp = "temp/" + (srialNumber++) + NumberUtils.getRandomInt(0, 10000000) + ".htm";
		StringBuffer sb = new StringBuffer("");
		sb.append("<html><head><title>TITLE</title>")
			.append("<link href='../fCharts/styles/chartsStyle.css' rel='stylesheet' type='text/css' />")
			.append("<script language='JavaScript' src='../fCharts/js/fCharts.js'></script>")
			.append("<script language='JavaScript' src='../fCharts/js/fChartsExportComponent.js'></script>")	
			.append("</head><body bgcolor='#ffffff' style='padding:1px;margin:40px;'>");
		sb.append("<div id=\"chartdiv121\" align=\"center\" style=\"width:100%;height:100%;overFlow:no;\">请您耐心等候,系统搜集数据中...</div>")
			.append("<script type=\"text/javascript\">")
			.append("var chart = new FusionCharts(\"../fCharts/swf/" + chart.getSwfName() + "\", \"myChartId121\", \"100%\", \"100%\");")
			.append("chart.setDataXML(\"" + chart.toString() + "\");")
			.append("chart.render(\"chartdiv121\");")
			.append("</script>");
		sb.append("</body></html>");
		File destFile = new File(pp + rp);
		TextUtils.overwriteToText(sb.toString(), destFile, "utf-8");
		return rp;
	}
}
